package com.qxzn.app.medicalhealth.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.jdsjlzx.interfaces.OnItemClickListener;
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
import com.github.jdsjlzx.interfaces.OnRefreshListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.qxzn.app.bean.RobotDeviceListBean;
import com.qxzn.app.medicalhealth.R;
import com.qxzn.app.medicalhealth.R2;
import com.qxzn.app.medicalhealth.adapter.AddedMedicalDeviceAdapter;
import com.qxzn.app.medicalhealth.adapter.MedicalDeviceAdapter;
import com.qxzn.app.page.BaseActivity;
import com.qxzn.app.page.activity.QrScanActivity;
import com.qxzn.app.util.AppUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 医疗设备列表
 */
public class MedicalDeviceActivity extends BaseActivity {

    @BindView(R2.id.iv_scan)
    ImageView ivScan;
    @BindView(R2.id.tv_scan)
    TextView tvScan;
    @BindView(R2.id.iv_device)
    ImageView ivDevice;
    @BindView(R2.id.tv_device)
    TextView tvDevice;
    @BindView(R2.id.lrv_medical_device)
    LRecyclerView lrvMedicalDevice;
    private LRecyclerViewAdapter recyclerViewAdapter;
    private MedicalDeviceAdapter adapter;
    private List<RobotDeviceListBean.DataBean> dataList = new ArrayList();
    private int page = 1;
    private int pageSize = 10;

    @Override
    protected int initLayout() {
        return R.layout.activity_medical_device;
    }

    @Override
    protected void initView() {
        lrvMedicalDevice.setLayoutManager(new LinearLayoutManager(this));
        lrvMedicalDevice.setNestedScrollingEnabled(false);
        adapter = new MedicalDeviceAdapter(this, dataList);
        recyclerViewAdapter = new LRecyclerViewAdapter(adapter);
        lrvMedicalDevice.setAdapter(recyclerViewAdapter);
        lrvMedicalDevice.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh() {
                AppUtil.showLog("setOnRefreshListener");
                page = 1;
//                getData();
            }
        });
        lrvMedicalDevice.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
                AppUtil.showLog("setOnLoadMoreListener");
                page++;
//                getData();
            }
        });
    }

    @Override
    protected void iniTitleBar() {
        tv_title.setText("医疗设备列表");
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        getData();
    }

    private void getData() {
        for (int i = 0; i < 4; i++) {
            RobotDeviceListBean.DataBean dataBean = new RobotDeviceListBean.DataBean();
            dataBean.setName("kasdfjka" + i);
            dataList.add(dataBean);
        }
        recyclerViewAdapter.notifyDataSetChanged();
    }

    @OnClick({R2.id.ll_scan, R2.id.ll_device})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.ll_scan) {
            startActivityForResult(new Intent(MedicalDeviceActivity.this, QrScanActivity.class), 1);
        } else if (i == R.id.ll_device) {
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 1) {

            }
        }
    }
}
